<?
class DateFunction{
        var $full_month = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
        var $short_month = array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
		
		var $full_month_en = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		var $short_month_en = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"," Sep"," Oct"," Nov"," Dec");
		public function getFullmonth(){
		    return $this->full_month;
		}
		
		public function getDate($date,$m){
		$show = explode("-",$date);
		$mon = $show[1]-1;
		$year = $show[0]+543;
		if($m=="M")
		   $month = $this->full_month[$mon];
		else $month = $this->short_month[$mon];
		return  sprintf("%d",$show[2])." $month $year";
		}
		
		public function getDate_withtext($date,$m){
		$show = explode("-",$date);
		$mon = $show[1]-0;
		$year = $show[0]+543;
		if($m=="M")
		   $month = $this->full_month[$mon];
		else $month = $this->short_month[$mon];
		return  "วันที่ ".sprintf("%d",$show[2])." เดือน $month พ.ศ. $year";
		}
		
		public function getDatetoSave($date){
		   $d = explode("-",$date);
		   $day = $d[0];
		   $month = $d[1];
		   $year = $d[2]-543;
		   return "$year-$month-$day";
		}
		
		public function getDatetoShow($date){  // สำหรับปีค.ศ.แสดงเป็นแบบ ไทย
		   $d = explode("-",$date);
		   $day = $d[2];
		   $month = $d[1];
		   $year = $d[0]+543;
		   return "$day-$month-$year";
		}
		
		//ปฏิทิน
		public function getDatetime_Singleline($date,$m){
            if($date!=""){
                $dn = explode("-",$date);
                $time = explode(" ",$dn[2]);
                $dn2 = $dn[1]-1; //เดือน
                if($m=="M_th")  $month = $this->full_month[$dn2];
                else  if($m=="M_en") $month = $this->full_month_en[$dn2];
				else  if($m=="m_en") $month = $this->short_month_en[$dn2];
				else $month = $this->short_month[$dn2];
				
                    $year = $dn[0]+543; //year
                    $t = explode(":",$time[1]);
                    $day  = sprintf("%d",$time[0]);
					
			    $msg = "$day $month $year $t[0]:$t[1]";;
			}else $msg = "ยังไม่มีข้อมูล";
            return  $msg;
		}
		
		public function getDatetime_Mutiline($date,$m){
		$dn = explode("-",$date);
		$time = explode(" ",$dn[2]);
		$dn2 = $dn[1]-0; //เดือน
		$year = $dn[0]+543; //year
		$t = explode(":",$time[1]);
		return  "$time[0] $mon[$dn2] $year<br> เวลา $t[0]:$t[1] น.";
		}
		
		public function getDatetime_Todate($date,$mon){
		$dn = explode("-",$date);
		$time = explode(" ",$dn[2]);
		$dn2 = $dn[1]-1; //เดือน
		$year = $dn[0]+543; //year
		$t = explode(":",$time[1]);
		return  "$time[0] $mon[$dn2] $year";
		}
		
		function format_datetimetoday($date,$mon){
			$dn = explode("-",$date);
			$time = explode(" ",$dn[2]);
			$dn2 = $dn[1];
			$dn2 = sprintf("%d",$dn2-0); //เดือน
			 if($m=="M_th")  $month = $this->full_month[$dn2];
                else  if($m=="M_en") $month = $this->full_month_en[$dn2];
				else  if($m=="m_en") $month = $this->short_month_en[$dn2];
				else $month = $this->short_month[$dn2];
				
			$day = sprintf("%d",$time[0]);
			$year = $dn[0]+543; //year
			$t = explode(":",$time[1]);
			
			$d = date("d");
			$m = date("m")-1;
			$y = date("Y")+543;
			$ded = $d-1;
			if($d==$day and $m==$dn2 and $y=$year){ $namedate = "<font color=#0000FF>วันนี้</font>"; }
			else if($ded==$day and $m==$dn2 and $y=$year){ $namedate = "<font color=#0000FF>เมื่อวานนี้</font>"; }
			else{ $namedate = "$day $month $year"; }
			return  "$namedate เวลา $t[0]:$t[1] น.";
		}
		
		public function getShow_date($date_input,$day_start,$day_stop){
			$date_in=explode("-",$date_input);
			$toDay = date("Y-m-d");
			$today_start1= mktime(0,0,0,date("m") ,date("d")-$day_start,date("Y")); 
			$today_start=date("Y-m-d",$today_start1 );
			$today_stop1 = mktime(0,0,0,date("m") ,date("d")+$day_stop,date("Y")); 
			$today_stop=date("Y-m-d",$today_stop1 );
			$start_day = mktime(0,0,0,$date_in[1],$date_in[2]-$day_start,$date_in[0]); 
			$show_start=date("Y-m-d",$start_day );
			$stop_day = mktime(0,0,0,$date_in[1],$date_in[2]+$day_stop,$date_in[0]); 
			$show_stop=date( "Y-m-d",$stop_day ); 
			
			
            if(($show_start>=$today_start and $start_day<=$toDay) or ($show_stop<=$today_stop and $show_stop>=$toDay) ){     
			   $show="show";
			}
		return $show;
			}	
}
?>